<template>
	<view>

		<view class="row b-b">
			<text class="tit">姓名</text>
			<input class="input" type="text" v-model="name" placeholder="请输入您的姓名" placeholder-class="placeholder" />
		</view>

		<view class="row b-b">
			<text class="tit">联系方式</text>
			<input class="input" type="number" maxlength="11" v-model="mobile" placeholder="请输入您的联系方式" placeholder-class="placeholder" />
		</view>

		<view class="row b-b">
			<text class="tit">您的需求</text>
			<textarea auto-height disable-default-padding auto-focus show-confirm-bar placeholder="您的需求" class="input"
				v-model="introduce"></textarea>
		</view>

		<view class="add-btn" @tap="lssue">提交</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		data() {
			return {
				id: 0,
				name: '',
				mobile: '',
				introduce: ''
			}
		},
		components: {

		},
		computed: {
			...mapState(['hasLogin'])
		},

		onLoad: function(option) { //option为object类型，会序列化上个页面传递的参数
			let result = this.$api.isLogin();
			if (result === false) {
				return false;
			}

			this.id = option.id
		},
		methods: {
			...mapMutations(['login', 'logout']),

			async lssue() {
				if (!this.name) {
					this.$api.msg('请输入您的姓名')
					return false;
				}
				if (!this.mobile) {
					this.$api.msg('请输入您的联系方式')
					return false;
				}

				let res = await this.$myRequest({
					url: '/add_contact',
					methods: "POST",
					data: {
						token: uni.getStorageSync('token'),
						product_id: this.id,
						name: this.name,
						mobile: this.mobile,
						introduce: this.introduce
					}
				})
				
				this.$api.msg(res.data.msg)
				setTimeout(() => {
					uni.redirectTo({
						url: '/pages/business/detail?id=' + this.id
					})
				}, 1500)
			},
		}
	}
</script>
<style lang='scss'>
	page {
		background: #f1f1f1;
	}

	.row {
		display: flex;
		align-items: center;
		position: relative;
		padding: 20rpx;
		height: 100%;
		background: #fff;
		border-bottom: 1rpx solid #e5e5e5;

		// margin-top: 10rpx;
		.tit {
			flex-shrink: 0;
			width: 140upx;
			font-size: 30upx;
			color: #303133;
			text-align-last: justify;
			margin-right: 10px;
		}

		.input {
			flex: 1;
			font-size: 30upx;
			color: #303133;
		}

		.icon-shouhuodizhi {
			font-size: 36upx;
			color: #909399;
		}
	}

	.default-row {
		margin-top: 20upx;

		.tit {
			flex: 1;
		}

		switch {
			transform: translateX(16upx) scale(.9);
		}
	}

	.add-btn {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 690upx;
		height: 80upx;
		margin: 60upx auto;
		font-size: 32upx;
		letter-spacing: 4upx;
		color: #fff;
		background-color: #e80909;
		border-radius: 50upx;
		box-shadow: 1px 2px 5px #dadada;
	}
</style>